Skip to content

runtime, runtime/pprof: add Func.Entry and goroutine labels - #5646

Merged
deadprogram merged 1 commit into
tinygo-org:devfrom
0magnet:runtime-entry-pprof-stubs
Oct 1, 2026
Merged

deadprogram merged 1 commit into
tinygo-org:devfrom
0magnet:runtime-entry-pprof-stubs

Conversation

@0pcom

@0pcom 0pcom commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5761.

Two source compatibility gaps, found while compiling larger Go programs under
TinyGo.

runtime.Func.Entry is stubbed like the rest of runtime.Func. testify's mock
package calls FileLine(f.Entry()).

runtime/pprof gains the goroutine label API that grpc references. It is
upstream's pre-1.24 implementation, because Go 1.24 moved the label type into
internal/runtime/pprof/label, which TinyGo does not have. The label set lives
in the context, so none of it needs the runtime. SetGoroutineLabels stays a
no-op, since TinyGo's profiler is itself a stub and nothing would read the
labels back.

Verified against host Go running the same program. Label lookup, ForLabels
ordering and early stop, child override with the parent left intact, Do
inheriting and not leaking, and the odd-argument panic all match. Also builds
for -target=wasm.

@davecheney davecheney left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this.
https://cs.opensource.google/go/go/+/refs/tags/go1.27.1:src/runtime/pprof/label.go;l=141

The upstream label support seems, at least superficially, to be propogated through context.Context so possibly we can just take the upstream version whole cloth. This would be a larger change, but i'm not convinved adding an inert label implementation wouldnt just add more complications down the line

@0pcom

0pcom commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

Agreed, and done in bab208b6. The inert label implementation is gone.

label.go is now upstream's, in its pre-1.24 form — Go 1.24 moved the label
type into internal/runtime/pprof/label, which TinyGo does not have, so the
self-contained version is the one that ports. Labels, WithLabels, Label,
ForLabels and Do are exactly upstream: the label set travels in the
context.Context and nothing in it touches the runtime.

SetGoroutineLabels is the one piece that stays a no-op, and I think it has
to. Upstream it exists only to hand the label map to the runtime via
runtime_setProfLabel so the CPU and goroutine profilers can attach it to
their samples. TinyGo has no such profiler — StartCPUProfile and Lookup
in src/runtime/pprof/pprof.go are themselves stubs — so a real
implementation would store a pointer on every task.Task that nothing ever
reads back. That seemed like the wrong trade for a value no profiler
consumes; it can become real alongside goroutine profiling. Everything the
API exposes to the program is unaffected, since that all travels in the
context.

Checked by building a program against a patched TinyGo root and running the
same program on host Go: identical output for label lookup, ForLabels
ordering and early stop, child override with parent left intact, Do
inheriting and not leaking, and the odd-argument panic. It also builds for
-target=wasm.

@0pcom 0pcom changed the title runtime, runtime/pprof: add Func.Entry and goroutine-label stubs runtime, runtime/pprof: add Func.Entry, and goroutine labels Sep 28, 2026
Comment thread src/runtime/stack.go Outdated

// Entry returns the entry address of the function. Stubbed like the rest of
// runtime.Func on TinyGo; provided so callers that reference it (e.g.
// github.com/stretchr/testify/mock via FileLine(f.Entry())) compile.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather avoid mentioning unrelated 3rd party libs

runtime.Func.Entry is stubbed like the rest of runtime.Func. testify's mock
package calls FileLine(f.Entry()).

runtime/pprof gains the goroutine label API that grpc references. It is
upstream's pre-1.24 implementation, because Go 1.24 moved the label type into
internal/runtime/pprof/label, which TinyGo does not have. The label set lives
in the context, so none of it needs the runtime. SetGoroutineLabels stays a
no-op, since TinyGo's profiler is itself a stub and nothing would read the
labels back.
@0pcom 0pcom changed the title runtime, runtime/pprof: add Func.Entry, and goroutine labels runtime, runtime/pprof: add Func.Entry and goroutine labels Sep 30, 2026
@0pcom
0pcom force-pushed the runtime-entry-pprof-stubs branch from bab208b to 56495f1 Compare September 30, 2026 18:30

@davecheney davecheney left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you, this seems pretty self contained.

@deadprogram

Copy link
Copy Markdown
Member

Thank you for the improvement @0pcom and to @davecheney and @b0ch3nski for review. Now merging.

@deadprogram
deadprogram merged commit fb7337a into tinygo-org:dev Oct 1, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

runtime, runtime/pprof: Func.Entry and the goroutine label API are missing

4 participants